<template>
<div>
  <myheader></myheader>
  <van-tabs v-model="active">
    <van-tab title="用户登录">
      <van-form @submit="login1">
        <van-field
          v-model="from.username"
          name="username"
          label="用户名"
          placeholder="用户名"
          :rules="[{ required: true, message: '请填写用户名' }]"
        />
        <van-field
          v-model="from.password"
          type="password"
          name="password"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit">登录</van-button>
        </div>
      </van-form>
    </van-tab>
    <van-tab title="手机号登录">
      <van-form>
        <van-field
          v-model="mobile"
          name="mobile"
          label="手机号"
          placeholder="手机号"
          :rules="[{ required: true, message: '请填写手机号' }]"
        />
        <van-button color="linear-gradient(to right, #ff6034, #ee0a24) " style="margin-left: 100px" @click="gain">
          获取验证码
        </van-button>
        <van-field
          v-model="code"
          name="code"
          label="验证码"
          placeholder="验证码"
          :rules="[{ required: true, message: '请填写验证码' }]"
        />
        <div style="margin: 16px;">
          <van-button round block type="info" native-type="submit" @click="login2">登录</van-button>
        </div>
      </van-form>
    </van-tab>
  </van-tabs>
</div>
</template>

<script>
import myheader from "./myheader"
export default {
  name: "Log",
  data(){
    return{
      from:{},
      mobile:'',
      code:''
    }
  },
  methods:{
    login1(){
      this.$axios.post('users/login1',this.from).then(res=>{
        if(res.data.code==200){
          alert("登陆成功")
        }else{
          alert(res.data.matter)
        }
      })
    },
    login2(){
      this.$axios.post('users/login2',{'mobile':this.mobile,'code':this.code}).then(res=>{
        if(res.data.code==200){
          alert('登陆成功')
        }else{
          alert(res.data.matter)
        }
      })
    },
    gain(){
      this.$axios.post('users/gain',{'mobile':this.mobile}).then(res=>{
        if(res.data.code==200){
          alert(res.data.smscode)
        }else{
          alert(res.data.mes)
        }
      })
    }
  },
  components:{
    'myheader':myheader
  }
}
</script>

<style scoped>

</style>
